var countdownstart;
var epochtimemilliseconds = GetCookie();
var nowdate = new Date();
var nowtime = nowdate.getTime();
var redirect_url = "http://extremebittorrent.com/index.html";

if (epochtimemilliseconds > 0)
{
	milliseconds_elapsed = nowtime - epochtimemilliseconds;
	if (milliseconds_elapsed >= 86400000) //86400 seconds in 1 day, times 1000 milliseconds/second
	{
		location.replace(redirect_url);
	}
	else { countdownstart = Math.round((86400000 - milliseconds_elapsed)/1000); }
}
else
{
	countdownstart = 86400;
	WriteCookie("etmindx", nowtime);
}

function WriteCookie(name,value) 
{
	var exp = '';
	var cookieExpiration = 365; // days
	var today = nowdate;
	var expdate = nowtime + (cookieExpiration * 24 * 60 * 60 * 1000);
	today.setTime(expdate);
	exp = '; expires=' + today.toGMTString();
	document.cookie = name + "=" + value + '; path=/' + exp;
}

function GetCookie()
{
	var cookiecontent;
	if(document.cookie.length > 0) 
	{
		var cookiename = 'etmindx=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		if(cookiebegin > -1) 
  		{
      			cookiebegin += 8;
      			cookieend = document.cookie.indexOf(";",cookiebegin);
      			if(cookieend < cookiebegin) 
      			{ 
      				cookieend = document.cookie.length; 
			}
			cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
		else { cookiecontent = 0; }
	}
	else { cookiecontent = 0; }
	return cookiecontent;
}

var _countDowncontainer=0;
var _currentSeconds=0;

function ActivateCountDown(strContainerID, initialValue) {
_countDowncontainer = document.getElementById(strContainerID);

if (!_countDowncontainer) {
alert("count down error: container does not exist: "+strContainerID+
"\nmake sure html element with this ID exists");
return;
}

SetCountdownText(initialValue);
window.setTimeout("CountDownTick()", 1000);
}

function CountDownTick() {
if (_currentSeconds <= 0) {
location.replace(redirect_url); //alert("your time has expired!");
return;
}

SetCountdownText(_currentSeconds-1);
window.setTimeout("CountDownTick()", 1000);
}

function SetCountdownText(seconds) {
//store:
if (seconds < 1) { location.replace(redirect_url); }
_currentSeconds = seconds;

//get minutes:
var minutes=parseInt(seconds/60);

//shrink:
seconds = (seconds%60);

//get hours:
var hours=parseInt(minutes/60);

//shrink:
minutes = (minutes%60);

//build text:
var strText = AddZero(hours) + " <span style='color:black'>hours</span> " + AddZero(minutes) + " <span style='color:black'>min</span> " + AddZero(seconds) + " <span style='color:black'>sec remaining</span>";

//apply:
_countDowncontainer.innerHTML = strText;
}

function AddZero(num) {
return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}

function WindowLoad(event) {
ActivateCountDown("CountDownPanel", countdownstart);
}
